#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "rngs.h"

#define DEBUG 0
#define NOISY_TEST 1

// Function being tested: int gainCard(...) {...}

int TgainCard(int supplyPos, struct gameState *state, int toFlag, int player)
{
  int g;
  int oldDeckCount = state->deckCount[player];
  int oldHandCount = state->handCount[player];
  int oldDiscardCount = state->discardCount[player];
  int oldSupplyCount = state->supplyCount[supplyPos];
  g = gainCard(supplyPos, state, toFlag, player);
  if(supplyPos > 0){
    if(toFlag == 0){
      assert(state->discardCount[player] == (oldDiscardCount + 1));
	  assert(state->supplyCount[supplyPos] == (oldSupplyCount - 1));
	  }
	else if(toFlag == 1){
      assert(state->deckCount[player] == (oldDeckCount + 1));
	  assert(state->supplyCount[supplyPos] == (oldSupplyCount - 1));
	  }
	else if(toFlag == 2){
      assert(state->handCount[player] == (oldHandCount + 1));
	  assert(state->supplyCount[supplyPos] == (oldSupplyCount - 1));
	  }
  }
  return 0;
}


int main()
{
  int x, y, randomToFlag, randomPlayer, randomSupplyPos;
  struct gameState newGame;
  printf("Now Testing: int gainCard(...) {...}\n");

  SelectStream(2);
  PutSeed((long)14);

  for(x = 0; x < 1000; x++){
    for (y = 0; y < sizeof(struct gameState); y++){
      ((char*)&newGame)[y] = Random() * 100;
    }
    randomToFlag = floor(Random() * 3);
    randomPlayer = floor(Random() * MAX_PLAYERS);
    randomSupplyPos = floor(Random() * 2);
    newGame.handCount[randomPlayer] = Random() * MAX_HAND;
    newGame.deckCount[randomPlayer] = Random() * MAX_DECK;
    newGame.discardCount[randomPlayer] = Random() * MAX_PLAYERS;
    TgainCard(randomSupplyPos, &newGame, randomToFlag, randomPlayer);
  }

  printf("Everything checks out according to this test.\n");

  return 0;
}
